use async_trait::async_trait;
use base_data::channel::EndReason;
use tools::ResultNull;
use tracing::info;

use crate::{
	business::{
		bus_trait::Business,
		inbound400::context::{BusinessState, InboundRunContext},
	},
	config::business_config,
	link_to_sip::play_sound_file_to_caller,
};

#[derive(Debug, Clone)]
pub struct NoAllowCaller;

#[async_trait]
impl Business for NoAllowCaller {
	type C = InboundRunContext;

	async fn play_back_stop(&self, context: &mut Self::C,_channel_id:u32) -> ResultNull {
		context.business_state = BusinessState::End(EndReason::TalkNocallerd);

		Ok(())
	}

	async fn hangup(
		&self,
		context: &mut Self::C,
		_channel_id: u32,
		_reason: EndReason
	) -> ResultNull {
				info!("无权呼叫,收到挂断消息");

		context.business_state = BusinessState::End(EndReason::TalkNocallerd);

		Ok(())
	}

	async fn start_call(&self, context: &mut Self::C) -> ResultNull {
		play_sound_file_to_caller(
			context.caller_channel(),
			business_config().not_allow_caller_bell_path,
		)?;

		Ok(())
	}
}
